from fdfs_client.client import Fdfs_client
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from apps.goods.models import SPUSpecification, SPU, SKUImage, SKU
from apps.meiduo_admin.serializer.shop import SPUSpecSerializer, SPUSerializer, ImageSerializer, SKUSerializer
from apps.meiduo_admin.utils import PageNum
from meiduo_mall import settings


class SpecView(ModelViewSet):
    queryset = SPUSpecification.objects.all().order_by('id')
    serializer_class = SPUSpecSerializer
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

    def simple(self, request):
        spus = SPU.objects.all()
        ser = SPUSerializer(spus, many=True)
        return Response(ser.data)


class ImageView(ModelViewSet):
    queryset = SKUImage.objects.all().order_by('id')
    permission_classes = [IsAdminUser]
    pagination_class = PageNum
    serializer_class = ImageSerializer

    def simple(self, request):
        skus = SKU.objects.all()
        ser = SKUSerializer(skus, many=True)
        return Response(ser.data)


